package thread;

public class SyncDemo3 {
    public static void main(String[] args) {
        Thread t1 = new Thread(){
            public void run(){
                Foo.dosome();
            }
        };

        Thread t2 = new Thread(){
            public void run(){
                Foo.dosome();
            }
        };

        t1.start();
        t2.start();
    }
}

class Foo{
    public synchronized static void dosome(){
        try {
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+"正在执行dosome方法");
            Thread.sleep(5000);
            System.out.println(t.getName()+"执行结束");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}